package heven.holt.wan.android.repository

import androidx.paging.Pager
import androidx.paging.PagingConfig
import heven.holt.wan.android.api.ApiWanQaServer
import heven.holt.wan.android.paging.source.WanQaQuizPagingSource
import heven.holt.wan.android.paging.source.WanQaSquarePagingSource

class WanQaRepository(
    private val apiWanQaServer: ApiWanQaServer
) {

    companion object {
        private const val PAGE_SIZE = 20
    }

    /**
     * 获取问答列表
     */
    fun getQaQuizeArticleList() = Pager(
        config = PagingConfig(
            initialLoadSize = 10,
            prefetchDistance = 5,
            enablePlaceholders = false,
            pageSize = PAGE_SIZE
        )
    ) {
        WanQaQuizPagingSource(apiWanQaServer)
    }.flow

    /**
     * 获取广场列表
     */
    fun getQaSquareArticleList() = Pager(
        config = PagingConfig(
            initialLoadSize = 10,
            prefetchDistance = 5,
            enablePlaceholders = false,
            pageSize = PAGE_SIZE
        )
    ) {
        WanQaSquarePagingSource(apiWanQaServer)
    }.flow
}